package com.johnguo.cretatefile;

import java.util.Properties;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.Producer;

public class ProducerDemo {
	public static void main(String... args) {
		Properties props = new Properties();
		props.put("bootstrap.servers", "master:9092");
		props.put("acks", "all");
		props.put("retries", 0);
		props.put("batch.size", 16384);
		props.put("linger.ms", 1);
		props.put("buffer.memory", 33554432);
		props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
		props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

		Producer<String, String> producer = new KafkaProducer<>(props);
		int n = 0;
		while(n<100*10000) {
				String record = CreateFileSale.getRecord();
				producer.send(new ProducerRecord<String, String>("input_topic",Integer.toString(1), record));
				System.out.println("写入条数据:" + record);
				n++;
		}
		producer.close();
	}
}
